;
(function($) {

	var AjaxAction = function(respData, extActions, targetObject) {
		var me = this;
		me.targetObject = targetObject;
		respData = respData || {};
		if (typeof data == "string") {
			respData = {
				data : respData,
				action : "string",
				state : 200
			};
		}
		$.extend(me, {}, respData);
		$.extend(me.actions, {}, extActions);
		return me;
	};
	$.extend(AjaxAction.prototype, {
		actions : {
			info : function() {
				var message = this.message;
				// 处理信息，如淡入淡出提示
			},
			warn : function() {
				var message = this.message || "业务请求失败";
				// 处理信息
			},
			error : function() {
				var message = this.message || "业务请求失败";
				// 处理信息
			},
			redirect : function() {
				var url = this.message || this.data || location.href;
				url && (window.location.href = url);
			},
			refresh : function() {
				location.reload();
			},
			topRedirect : function() {
				var url = this.message || this.data || top.location.href;
				url && (top.location.href = url);
			},
			login : function() {
				// 处理登录
			},
			filedsError : function() {
				// 处理字段异常
			},
			string : function() {
				// 处理字符串
			}
		},
		invoke : function() {
			var me = this;
			var action = me.actions[data.state] || me.actions[data.action]
					|| me.actions["info"];
			action && action.call(me);
		}
	});
	AjaxAction.actons["302"] = AjaxAction.actons["redirect"];
	AjaxAction.actons["403"] = AjaxAction.actons["login"];
	AjaxAction.actons["503"] = AjaxAction.actons["error"];

	$.ajaxAction = function(url, data, targetObject) {
		var config = url;
		if (typeof url == "string") {
			config = {
				url : url,
				data : data
			};
		}
		var defaultAjaxOptions = {
			type : "POST",
			dataType : "jsonp",
			jsonp : "_callback",
			cache : false,
			success : function(data, status, xhr) {
				new AjaxAction(data, config.extActions, targetObject).invoke();
			},
			error : function(xhr, errorType, error) {
				var data = {
					state : 503,
					errorType : errorType,
					message : error
				};
				new AjaxAction(data, config.extActions, targetObject).invoke();
			}
		}, options = $.extend({}, defaultAjaxOptions, {
			url : config.url,
			data : config.data
		});
		$.ajax(options);
	};
	$.ajaxAction.extend = function(extActions) {
		$.extend(AjaxAction.actions.prototype, extActions);
	};
})(this.jQuery || this.Zepto);
